package gupaoedu.LazySingleton;

import gupaoedu.enumSingleton.EnumSingleton;

import java.lang.reflect.Constructor;

/**
 * gupaoedu.LazySingleton
 * linwenjie
 * 2019-06-19
 *
 * 反射破坏单例模式
 */
public class ReflactSingletonTest {
    public static void main(String[] args) {
        try {


            Class<?> clazz = EnumSingleton.class;

            //获取构造函数
            Constructor c = clazz.getDeclaredConstructor(null);
            //允许构造函数可以访问
            c.setAccessible(true);

            Object o1 = c.newInstance();

            Object o2 = c.newInstance();

            System.out.println(o1);
            System.out.println(o2);
            System.out.println(o1==o2);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
